package com.leetcode.根据数据结构分类.哈希表;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author: ZhouBert
 * @date: 2020/12/20
 * @description: 剑指 Offer 50. 第一个只出现一次的字符
 * https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/
 */
public class A_剑指_Offer_50_第一个只出现一次的字符 {

    public char firstUniqChar(String s) {
        LinkedHashMap<Character, Integer> map = new LinkedHashMap<Character, Integer>();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (map.containsKey(chars[i])) {
                map.put(chars[i], map.get(chars[i]) + 1);
            } else {
                map.put(chars[i], 1);
            }
        }
        char res=' ';
        for (Map.Entry<Character, Integer> item :
                map.entrySet()) {
            if (item.getValue() == 1){
                res=item.getKey();
                break;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(1);
    }
}
